home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / C / SetAlternate.c < prev    next >
C/C++ Source or Header  |  1986-04-02  |  4KB  |  136 lines

  1.  
  2. /* SetAlternate.c */
  3.  
  4. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  5. /* (c) Copyright 1986 John A. Toebes, VIII   All rights reserved         */
  6. /*     120-H Northington Place,   Cary NC 27511   (919) 469-4210         */
  7. /*  This program may be used and modified for any purpose so long as     */
  8. /*  this copyright notice remains with the code and the program is not   */
  9. /*  sold and no charge is made for its use.                              */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. /*
  13.  
  14. In making some enhancements to the Icons for Hack, I wrote a very simple
  15. utility that you may find useful.  Normally, the Icon editor only lets you
  16. create icons whose selected action is either to reverse the image or provide
  17. backfill.However, in the gadget structure for the Icon is the ability to put
  18. an alternate image as found in any gadget.  To use it you simply have to
  19. supply an alternate image and set the appropriate bits in the structure.
  20.  
  21.  
  22. Unfortunately ICONED fails to provide an easy way to do this so I wrote a Q&D
  23. tool to combine two icons into a single one with the second being an alternate
  24. image for the first.
  25.  
  26. To use it, first compile the program (It works under Lattice, have no idea
  27. about MANX) and link it.
  28.  
  29. Then create two icons for the one you want.  Make the first the normal image
  30. and the second the alternate image.  When saving them make sure you set the
  31. frame the same for both or the results will be an alternate image slightly
  32. out of wack (and I don't mean the debugger) with the first.  Lets assume
  33. the first is called 'primary' and the second 'alternate'.  At this point
  34. there will be four files on disk:
  35.  
  36.     primary
  37.     primary.info
  38.     secondary
  39.     secondary.info
  40.  
  41. Now run the SetAlternate program with
  42.  
  43.    SetAlternate primary secondary
  44.  
  45. The primary icon will now display the second one when you hit on it.  Note
  46. that since the image was copied, you can delete the second one ('secondary'
  47. in this case) without any effect.  Note however that ICONED does not know
  48. exactly what to do with the alternate image so you lose it if you edit the
  49. Icon.  Have no fear, just run the program again to reset the alternate.  Also
  50. there are no side effects from running SetAlternate over and over on the
  51. same icons (other than waste time).
  52.  
  53. */
  54.  
  55. #include <stdio.h>
  56. #include <exec/types.h>
  57. #include <workbench/workbench.h>
  58. #include <workbench/icon.h>
  59. #include <workbench/startup.h>
  60.  
  61. int IconBase;
  62. extern  struct WBStartup *WBenchMsg;
  63.  
  64. main(argc,argv)
  65. int argc;
  66. char *argv[];
  67. {
  68.  
  69. struct DiskObject *diskobja, *diskobj, *GetDiskObject();
  70. APTR saveimage;
  71. USHORT saveflags;
  72.  
  73. /* make sure we ran from CLI */
  74. if (argc == 0)
  75.    exit(1);
  76.  
  77. /* make sure they specified two icons */
  78. if (argc != 3)
  79.    {
  80.    printf("Usage: %s <icon> <icona>\n", argv[0]);
  81.    exit(2);
  82.    }
  83.  
  84. /* make the icon library available to us */
  85. if ( (IconBase = OpenLibrary( ICONNAME, 1)) == NULL)
  86.    exit(2);
  87.  
  88. /* read the icon to modify from disk */
  89. if ( (diskobj = GetDiskObject(argv[1])) == NULL)
  90.    {
  91.    printf("Cannot read icon for %s\n", argv[1]);
  92.    CloseLibrary( IconBase );
  93.    exit(3);
  94.    }
  95.  
  96. /* read the second icon to get its image */
  97. if ( (diskobja = GetDiskObject(argv[2])) == NULL)
  98.    {
  99.    printf("Cannot read icon for %s\n", argv[1]);
  100.    FreeDiskObject(diskobj);
  101.    CloseLibrary( IconBase );
  102.    exit(4);
  103.    }
  104.  
  105. /* remember what the original icon looked like */
  106. /* we will restore it before we do a FreeDiskObject on it */
  107. /* this way the system won't get confused as to which memory it */
  108. /* allocated for the structure */
  109.  
  110. saveimage = diskobj->do_Gadget.SelectRender;
  111. saveflags = diskobj->do_Gadget.Flags;
  112.  
  113. /* point the alternate image of the modified icon to that of the 2nd icon */
  114. diskobj->do_Gadget.SelectRender = diskobja->do_Gadget.GadgetRender;
  115.  
  116. /* modify the flags so that it used the alternate image */
  117. diskobj->do_Gadget.Flags = (saveflags & ~GADGHIGHBITS) | GADGHIMAGE;
  118.  
  119. /* now write the fixed icon to disk */
  120. if ( !PutDiskObject( argv[1], diskobj) )
  121.    printf("Cannot write new icon - code %d\n", IoErr() );
  122.  
  123. /* restore the original icon to what we read in */
  124. diskobj->do_Gadget.SelectRender = saveimage;
  125. diskobj->do_Gadget.Flags = saveflags;
  126.  
  127. /* and send it and the other object away */
  128. if ( diskobj)
  129.    FreeDiskObject( diskobj );
  130. if ( diskobja)
  131.    FreeDiskObject( diskobja );
  132. if ( IconBase)
  133.    CloseLibrary( IconBase );
  134. }
  135.  
  136.